Can I dynamicaly size a div based on discreet units and still center? [closed]

Posted by Dave on Pro Webmasters See other posts from Pro Webmasters or by Dave
Published on 2011-03-05T13:53:05Z Indexed on 2011/03/05 15:32 UTC
Read the original article Hit count: 173

Filed under:

Here's the problem: I have a website I'm working on that, depending on what the user has selected, will pop up a different number of boxes 80px high and 200px wide and currently set to float:left. These boxes are contained within a div that is basically the whole width of the screen minus some 1% margins.

So at the moment they all fill in the box and, depending on screen size, occupy a grid of variable height and width. The problem is, if the screen size makes the containing box, say, 700px wide then you end up with 3 boxes per row and a bloody big margin on the right.

What I would like to do is center the grid of boxes inside the containing box so that the margins are equal left and right. I suspect this can't be done since it means the containing box needs to set its size by looking both at the size of the user's window as well as the size of its children. It would be easy to do with javascript but I'd prefer not to if that is an option. If it is truly impossible then I will simply script it and let non-js users see a left-justified set of boxes.

© Pro Webmasters or respective owner

Related posts about css